package com.jfinal.core;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;

/**
 * Config 适配器(主要原因是Config作用于太小了)
 * 使用 adapter 必须在 jfinal.init 之后
 * @ClassName: ConfigAdapter 
 * @author huangx
 * @date 2015年2月6日 上午9:05:26
 */
public class ConfigAdapter {

	// my
	private Boolean devMode;
	// Field
	private Constants constants;
	private Routes routes;
	private Plugins plugins;
	private Interceptors interceptors;
	private Handlers handlers;

	private ConfigAdapter() {
	}

	private static ConfigAdapter me = new ConfigAdapter();

	public static ConfigAdapter on() {
		return me;
	}

	public Constants getConstants() {
		if (constants == null) constants = Config.getConstants();
		return constants;
	}

	public Routes getRoutes() {
		if (routes == null) routes = Config.getRoutes();
		return routes;
	}

	public Plugins getPlugins() {
		if (plugins == null) plugins = Config.getPlugins();
		return plugins;
	}

	public Interceptors getInterceptors() {
		if (interceptors == null) interceptors = Config.getInterceptors();
		return interceptors;
	}

	public Handlers getHandlers() {
		if (handlers == null) handlers = Config.getHandlers();
		return handlers;
	}

	/*------------------------- my ----------------------*/
	public Boolean getDevMode() {
		if (devMode == null) devMode = this.getConstants().getDevMode();
		return devMode;
	}
}
